{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useState, useEffect, useRef } from 'react';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport { addGlobalMouseDownEvent, getTargetFromEvent } from \"../utils/uiUtil\";\nexport default function usePickerInput(_ref) {\n  var open = _ref.open,\n    value = _ref.value,\n    isClickOutside = _ref.isClickOutside,\n    triggerOpen = _ref.triggerOpen,\n    forwardKeyDown = _ref.forwardKeyDown,\n    _onKeyDown = _ref.onKeyDown,\n    blurToCancel = _ref.blurToCancel,\n    onSubmit = _ref.onSubmit,\n    onCancel = _ref.onCancel,\n    _onFocus = _ref.onFocus,\n    _onBlur = _ref.onBlur;\n  var _useState = useState(false),\n    _useState2 = _slicedToArray(_useState, 2),\n    typing = _useState2[0],\n    setTyping = _useState2[1];\n  var _useState3 = useState(false),\n    _useState4 = _slicedToArray(_useState3, 2),\n    focused = _useState4[0],\n    setFocused = _useState4[1];\n  /**\n   * We will prevent blur to handle open event when user click outside,\n   * since this will repeat trigger `onOpenChange` event.\n   */\n\n  var preventBlurRef = useRef(false);\n  var valueChangedRef = useRef(false);\n  var preventDefaultRef = useRef(false);\n  var inputProps = {\n    onMouseDown: function onMouseDown() {\n      setTyping(true);\n      triggerOpen(true);\n    },\n    onKeyDown: function onKeyDown(e) {\n      var preventDefault = function preventDefault() {\n        preventDefaultRef.current = true;\n      };\n      _onKeyDown(e, preventDefault);\n      if (preventDefaultRef.current) return;\n      switch (e.which) {\n        case KeyCode.ENTER:\n          {\n            if (!open) {\n              triggerOpen(true);\n            } else if (onSubmit() !== false) {\n              setTyping(true);\n            }\n            e.preventDefault();\n            return;\n          }\n        case KeyCode.TAB:\n          {\n            if (typing && open && !e.shiftKey) {\n              setTyping(false);\n              e.preventDefault();\n            } else if (!typing && open) {\n              if (!forwardKeyDown(e) && e.shiftKey) {\n                setTyping(true);\n                e.preventDefault();\n              }\n            }\n            return;\n          }\n        case KeyCode.ESC:\n          {\n            setTyping(true);\n            onCancel();\n            return;\n          }\n      }\n      if (!open && ![KeyCode.SHIFT].includes(e.which)) {\n        triggerOpen(true);\n      } else if (!typing) {\n        // Let popup panel handle keyboard\n        forwardKeyDown(e);\n      }\n    },\n    onFocus: function onFocus(e) {\n      setTyping(true);\n      setFocused(true);\n      if (_onFocus) {\n        _onFocus(e);\n      }\n    },\n    onBlur: function onBlur(e) {\n      if (preventBlurRef.current || !isClickOutside(document.activeElement)) {\n        preventBlurRef.current = false;\n        return;\n      }\n      if (blurToCancel) {\n        setTimeout(function () {\n          var _document = document,\n            activeElement = _document.activeElement;\n          while (activeElement && activeElement.shadowRoot) {\n            activeElement = activeElement.shadowRoot.activeElement;\n          }\n          if (isClickOutside(activeElement)) {\n            onCancel();\n          }\n        }, 0);\n      } else if (open) {\n        triggerOpen(false);\n        if (valueChangedRef.current) {\n          onSubmit();\n        }\n      }\n      setFocused(false);\n      if (_onBlur) {\n        _onBlur(e);\n      }\n    }\n  }; // check if value changed\n\n  useEffect(function () {\n    valueChangedRef.current = false;\n  }, [open]);\n  useEffect(function () {\n    valueChangedRef.current = true;\n  }, [value]); // Global click handler\n\n  useEffect(function () {\n    return addGlobalMouseDownEvent(function (e) {\n      var target = getTargetFromEvent(e);\n      if (open) {\n        var clickedOutside = isClickOutside(target);\n        if (!clickedOutside) {\n          preventBlurRef.current = true; // Always set back in case `onBlur` prevented by user\n\n          requestAnimationFrame(function () {\n            preventBlurRef.current = false;\n          });\n        } else if (!focused || clickedOutside) {\n          triggerOpen(false);\n        }\n      }\n    });\n  });\n  return [inputProps, {\n    focused: focused,\n    typing: typing\n  }];\n}","map":{"version":3,"names":["_slicedToArray","useState","useEffect","useRef","KeyCode","addGlobalMouseDownEvent","getTargetFromEvent","usePickerInput","_ref","open","value","isClickOutside","triggerOpen","forwardKeyDown","_onKeyDown","onKeyDown","blurToCancel","onSubmit","onCancel","_onFocus","onFocus","_onBlur","onBlur","_useState","_useState2","typing","setTyping","_useState3","_useState4","focused","setFocused","preventBlurRef","valueChangedRef","preventDefaultRef","inputProps","onMouseDown","e","preventDefault","current","which","ENTER","TAB","shiftKey","ESC","SHIFT","includes","document","activeElement","setTimeout","_document","shadowRoot","target","clickedOutside","requestAnimationFrame"],"sources":["/data/messenger.client/node_modules/rc-picker/es/hooks/usePickerInput.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useState, useEffect, useRef } from 'react';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport { addGlobalMouseDownEvent, getTargetFromEvent } from \"../utils/uiUtil\";\nexport default function usePickerInput(_ref) {\n  var open = _ref.open,\n      value = _ref.value,\n      isClickOutside = _ref.isClickOutside,\n      triggerOpen = _ref.triggerOpen,\n      forwardKeyDown = _ref.forwardKeyDown,\n      _onKeyDown = _ref.onKeyDown,\n      blurToCancel = _ref.blurToCancel,\n      onSubmit = _ref.onSubmit,\n      onCancel = _ref.onCancel,\n      _onFocus = _ref.onFocus,\n      _onBlur = _ref.onBlur;\n\n  var _useState = useState(false),\n      _useState2 = _slicedToArray(_useState, 2),\n      typing = _useState2[0],\n      setTyping = _useState2[1];\n\n  var _useState3 = useState(false),\n      _useState4 = _slicedToArray(_useState3, 2),\n      focused = _useState4[0],\n      setFocused = _useState4[1];\n  /**\n   * We will prevent blur to handle open event when user click outside,\n   * since this will repeat trigger `onOpenChange` event.\n   */\n\n\n  var preventBlurRef = useRef(false);\n  var valueChangedRef = useRef(false);\n  var preventDefaultRef = useRef(false);\n  var inputProps = {\n    onMouseDown: function onMouseDown() {\n      setTyping(true);\n      triggerOpen(true);\n    },\n    onKeyDown: function onKeyDown(e) {\n      var preventDefault = function preventDefault() {\n        preventDefaultRef.current = true;\n      };\n\n      _onKeyDown(e, preventDefault);\n\n      if (preventDefaultRef.current) return;\n\n      switch (e.which) {\n        case KeyCode.ENTER:\n          {\n            if (!open) {\n              triggerOpen(true);\n            } else if (onSubmit() !== false) {\n              setTyping(true);\n            }\n\n            e.preventDefault();\n            return;\n          }\n\n        case KeyCode.TAB:\n          {\n            if (typing && open && !e.shiftKey) {\n              setTyping(false);\n              e.preventDefault();\n            } else if (!typing && open) {\n              if (!forwardKeyDown(e) && e.shiftKey) {\n                setTyping(true);\n                e.preventDefault();\n              }\n            }\n\n            return;\n          }\n\n        case KeyCode.ESC:\n          {\n            setTyping(true);\n            onCancel();\n            return;\n          }\n      }\n\n      if (!open && ![KeyCode.SHIFT].includes(e.which)) {\n        triggerOpen(true);\n      } else if (!typing) {\n        // Let popup panel handle keyboard\n        forwardKeyDown(e);\n      }\n    },\n    onFocus: function onFocus(e) {\n      setTyping(true);\n      setFocused(true);\n\n      if (_onFocus) {\n        _onFocus(e);\n      }\n    },\n    onBlur: function onBlur(e) {\n      if (preventBlurRef.current || !isClickOutside(document.activeElement)) {\n        preventBlurRef.current = false;\n        return;\n      }\n\n      if (blurToCancel) {\n        setTimeout(function () {\n          var _document = document,\n              activeElement = _document.activeElement;\n\n          while (activeElement && activeElement.shadowRoot) {\n            activeElement = activeElement.shadowRoot.activeElement;\n          }\n\n          if (isClickOutside(activeElement)) {\n            onCancel();\n          }\n        }, 0);\n      } else if (open) {\n        triggerOpen(false);\n\n        if (valueChangedRef.current) {\n          onSubmit();\n        }\n      }\n\n      setFocused(false);\n\n      if (_onBlur) {\n        _onBlur(e);\n      }\n    }\n  }; // check if value changed\n\n  useEffect(function () {\n    valueChangedRef.current = false;\n  }, [open]);\n  useEffect(function () {\n    valueChangedRef.current = true;\n  }, [value]); // Global click handler\n\n  useEffect(function () {\n    return addGlobalMouseDownEvent(function (e) {\n      var target = getTargetFromEvent(e);\n\n      if (open) {\n        var clickedOutside = isClickOutside(target);\n\n        if (!clickedOutside) {\n          preventBlurRef.current = true; // Always set back in case `onBlur` prevented by user\n\n          requestAnimationFrame(function () {\n            preventBlurRef.current = false;\n          });\n        } else if (!focused || clickedOutside) {\n          triggerOpen(false);\n        }\n      }\n    });\n  });\n  return [inputProps, {\n    focused: focused,\n    typing: typing\n  }];\n}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